<div class="table-responsive">
    <table class="table table-hover">
        <thead>
            <tr>
                <th scope="col">标识</th>
                <th scope="col">名称</th>
                <th scope="col">头像</th>
                <th scope="col">手机号</th>
                {if session('adminLevel')}
                <th scope="col">所属分公司</th>
                {/if}
                <th scope="col">所属部门</th>
                <th scope="col">所属职位</th>
                <th scope="col">邮箱</th>
                <th scope="col" width="350">操作</th>
            </tr>
        </thead>
        <tbody>
            {volist name="card" id="vo"}
            <tr id="tr{$vo.id}">
                <th scope="row">{$vo.id}</th>
                <td>{$vo.name}</td>
                <td>
                    {if $vo.image}
                    <img src="__UPLOADS__/{$vo.image}" id="uploadres" alt="" width="20">
                    {else/}
                    <img src="__STATIC__/logo.png" id="uploadres" alt="" width="20" height="20">
                    {/if}
                </td>
                <td>{$vo.phone}</td>
                {if session('adminLevel')}
                <td>
                    {if $vo.company_id}
                    <a href="{:url('card/company',array('id'=>$vo['company_id']['id'],'name'=>$vo['company_id']['title']))}" class="btn btn-success btn-sm">{$vo.company_id.title}</a>
                    {else/}
                    <a href="{:url('card/edit',array('id'=>$vo['id']))}" class="btn btn-info btn-sm">去设置分公司</a>
                    {/if}
                </td>
                {/if}
                <td>
                    {if $vo.did}
                    <a href="{:url('card/depart',array('id'=>$vo['did']['id'],'name'=>$vo['did']['name']))}" class="btn btn-success btn-sm">{$vo.did.name}</a>
                    {else/}
                    <a href="{:url('card/edit',array('id'=>$vo['id']))}" class="btn btn-info btn-sm">去设置部门</a>
                    {/if}
                </td>
                <td>
                    {if $vo.job_id}
                    <a href="{:url('card/job',array('id'=>$vo['job_id']['id'],'name'=>$vo['job_id']['name']))}" class="btn btn-success btn-sm">{$vo.job_id.name}</a>
                    {else/}
                    <a href="{:url('card/edit',array('id'=>$vo['id']))}" class="btn btn-info btn-sm">去设置职位</a>
                    {/if}
                </td>
                <td>{$vo.email}</td>
                <td scope="row">
                    <a href="{:url('card/edit',array('id'=>$vo['id'],'did'=>$vo['did']['id']))}" class="btn btn-primary btn-sm">编辑</a>
                    <button type="button" class="btn btn-danger btn-sm" onclick="delThis('{$vo.id}')">删除</button>
                    <a href="{:url('card/getcode',array('id'=>$vo['id']))}" class="btn btn-info btn-sm" target="view_window">获取此人小程序码</a>
                    {if $vo.is_disabled}
                    <button type="button" class="btn btn-danger btn-sm" onclick="disabledThis('{$vo.id}',0)">禁用</button>
                    {else/}
                    <button type="button" class="btn btn-success btn-sm" onclick="disabledThis('{$vo.id}',1)">开启</button>
                    {/if}
                    {if $vo.is_top}
                    <button type="button" class="btn btn-danger btn-sm" onclick="topThis('{$vo.id}',0)">取消默认</button>
                    {else/}
                    <button type="button" class="btn btn-success btn-sm" onclick="topThis('{$vo.id}',1)">首页默认</button>
                    {/if}
                </td>

            </tr>
            {/volist}
        </tbody>
    </table>
</div>

{$card|raw}


<script>
    function delThis($id) {
        confirm('警告', '你正在进行删除操作，一旦删除将无法挽回！', function (isConfirm) {
            if (isConfirm) {
                $.post("{:url('card/del')}",
                    {
                        id: $id,
                    },
                    function (data, status) {
                        if (data == 1) {
                            alert("提示!", "已成功为你删除", function () {
                                $('#tr' + $id).remove();
                            }, {
                                type: 'success',
                                confirmButtonText: '确定'
                            });
                        }
                    }
                );
            }
        }, {
            confirmButtonText: '我确定',
            cancelButtonText: '取消操作',
            width: 400
        });
    }


    function disabledThis($id, $type) {
        if ($type) {
            $text = '你正在打算禁用此名片？';
        } else {
            $text = ' 你正在打算重新开启此名片？';
        }
        confirm('提示!', $text, function (isConfirm) {
            if (isConfirm) {
                $.post("{:url('card/disabled')}",
                    {
                        id: $id,
                        type: $type
                    },
                    function (data, status) {
                        if (data == 1) {
                            alert("提示!", "操作成功!刷新可见！", function () {
                                $('#tr' + $id).remove();
                            }, {
                                type: 'success',
                                confirmButtonText: '确定'
                            });
                        }
                    }
                );
            }
        }, {
            confirmButtonText: '我确定',
            cancelButtonText: '取消操作',
            width: 400
        });
    }

    function topThis($id, $type) {
        if ($type) {
            $text = '你打算把此名片默认在首页吗? ';
        } else {
            $text = '你正在取消此名片的首页默认？';
        }
        confirm('提示!', $text, function (isConfirm) {
            if (isConfirm) {
                $.post("{:url('card/top')}",
                    {
                        id: $id,
                        type: $type
                    },
                    function (data, status) {
                        if (data == 1) {
                            alert("提示!", "操作成功!刷新可见！", function () {
                                $('#tr' + $id).remove();
                            }, {
                                type: 'success',
                                confirmButtonText: '确定'
                            });
                        }
                    }
                );
            }
        }, {
            confirmButtonText: '我确定',
            cancelButtonText: '取消操作',
            width: 400
        });
    }
</script>